        $(document).ready(function(){
        
        
            //验证用户名
            $("#username_txb").focus(function(){
                check_username(1);
            }).blur(function(){
                check_username(2);
            })            
            
            //验证密码
            $("#password_txb").focus(function(){
                check_password(1);
            }).blur(function(){
                check_password(2);
            })
            
            //验证确认密码
            $("#querenpassword_txb").focus(function(){
                check_querenpassword(1);
            }).blur(function(){
                check_querenpassword(2);
            })
            
            //验证手机号码
            $("#shouji_txb").focus(function(){
                check_shouji(1);
            }).blur(function(){
                check_shouji(2);
            })
            
            //验证手机验证码
            $("#shouji_yzm_txb").focus(function(){
                //
            }).blur(function(){
                check_shoujiyzm();
            })
            
            //验证电子邮箱
            $("#email_txb").focus(function(){
                check_email(1);
            }).blur(function(){
                check_email(2);
            })
        })
          //验证绑定QQ注册
       function checkallregqq() 
        {
        return check_username(2)&&check_password(2)&&check_querenpassword(2)&&check_email(2);
        }
        //验证登录
        function checkalllog()
        { 
        var name= $("#logname").val();
        var pwd=$("#logpwd").val();
          if(name==""||pwd=="")
          {
          alert("用户名和密码不能为空！");
            return false;
          }
          else
          {
          return true;
          }
         
        }
        
        //设置显示消息
        function set_msg(msg_kongjian,msg_style,msg_text)
        {
            $(msg_kongjian).attr("class",msg_style);
            $(msg_kongjian).html(msg_text);
        }
        
        
        //验证所有
        function checkallreg()
        {
            return check_username(2)&&check_password(2)&&check_querenpassword(2)&&check_shouji(2)&&check_shoujiyzm()&&check_email(2);
        }
        
        //获取验证码
        function getyzm()
        {
            if(check_shouji(2) == false) return;
            htmlobj=$.ajax({url:"../js/ajax.aspx?type=8&phone_num="+ $("#shouji_txb").val(),async:false});
            var return_num=htmlobj.responseText;
           
           
            var kongjian_name="#shouji_yzm_txb";

            if(return_num==0)
            {
                //alert("未知错误！");
                set_msg(kongjian_name+"_msg","on_error on_show","未知错误");
            }
            if(return_num==1)
            {
                //alert("请输入您的手机号码！");
                set_msg(kongjian_name+"_msg","on_error on_show","请输入您的手机号码");
            }
            if(return_num==2)
            {
                //alert("手机号码格式不正确,请输入正确的手机号！");
                set_msg(kongjian_name+"_msg","on_error on_show","手机号码格式不正确,请输入正确的手机号！");
            }
            if(return_num==3)
            {
                //alert("该手机号码已经被使用，请更换！");
                set_msg(kongjian_name+"_msg","on_error on_show","该手机号码已经被使用，请更换！");
            }
            if(return_num==4)
            {
                //alert("发送间隔不能少于 180 秒！请稍后再试！");
                set_msg(kongjian_name+"_msg","on_error on_show","发送间隔不能少于 180 秒！请稍后再试！");
            }
            if(return_num==5)
            {
                //alert("验证码已经发送至您的手机！");
                set_msg(kongjian_name+"_msg","on_ok on_show","验证码已经发送至您的手机！");
                time();
            }
            if(return_num==6)
            {
                //alert("来路不正确！");
                set_msg(kongjian_name+"_msg","on_error on_show","来路不正确");
            }
        }
        
        
        function setxieyi()
        {
           var zhucexieyi=document.getElementById("zhucexieyi_tr");
           if(zhucexieyi.style.display=="none")
           {
              zhucexieyi.style.display="";
           }
           else
           {
              zhucexieyi.style.display="none";
           }
        }


        
        //用户名验证
        function check_username(check_type)
        {
            var kongjian_name="#username_txb";
            if(check_type==1)//onfocus
            {
                $(kongjian_name).css("background-color","#FEFFE3");
                set_msg(kongjian_name+"_msg","on_attention on_show","4-20个字符，一个汉字为2个字符。注册成功后不可修改");
            }
            else//onblur
            {
                $(kongjian_name).css("background-color","#FFF");
                var kongjian_vaule=$.trim($(kongjian_name).val());
                var kongjian_vaule_length=kongjian_vaule.length;
                if(kongjian_vaule_length==0)
                {
                    set_msg(kongjian_name+"_msg","on_error on_show","您还没有输入用户名");
                    return false;
                }
                else
                {
                    if(kongjian_vaule_length >= 4&&kongjian_vaule_length <= 20)
                    {
                        htmlobj=$.ajax({url:"http://localhost:8080/guanganren/user/user!check.do?type=user_id&user_id="+ encodeURI(encodeURI(kongjian_vaule)),async:false});
                        
                       
                        
                        if(htmlobj.responseText=="true")
                        {
                            set_msg(kongjian_name+"_msg","on_ok on_show","输入正确");
                            return true;
                        }
                        else
                        {
                            set_msg(kongjian_name+"_msg","on_error on_show","该用户名已经存在");
                            return false;
                        }
                    }
                    else
                    {
                        set_msg(kongjian_name+"_msg","on_error on_show","用户名需为4-20个字符(包括汉字、数字、字母、下划线，每个汉字为2字符)");
                        return false;
                    }
                }
            }
        }
        
        
        //密码验证
        function check_password(check_type)
        {
            var kongjian_name="#password_txb";
            if(check_type==1)//onfocus
            {
                $(kongjian_name).css("background-color","#FEFFE3");
                set_msg(kongjian_name+"_msg","on_attention on_show","密码需由6-20个字符（数字、字母、下划线）组成，区分大小写");
            }
            else//onblur
            {
                $(kongjian_name).css("background-color","#FFF");
                var kongjian_vaule=$.trim($(kongjian_name).val());
                var kongjian_vaule_length=kongjian_vaule.length;
                if(kongjian_vaule_length==0)
                {
                    set_msg(kongjian_name+"_msg","on_error on_show","您还没有输入密码");
                    return false;
                }
                else
                {
                    if(kongjian_vaule_length >= 6&&kongjian_vaule_length <= 20)
                    {
                        set_msg(kongjian_name+"_msg","on_ok on_show","输入正确");
                        return true;
                    }
                    else
                    {
                        set_msg(kongjian_name+"_msg","on_error on_show","密码需由6-20个字符组成");
                        return false;
                    }
                }
            }
        }
        
        
        //确认密码验证
        function check_querenpassword(check_type)
        {
            var kongjian_name="#querenpassword_txb";
            if(check_type==1)//onfocus
            {
                $(kongjian_name).css("background-color","#FEFFE3");
                set_msg(kongjian_name+"_msg","on_attention on_show","请再次输入您的密码");
            }
            else//onblur
            {
                $(kongjian_name).css("background-color","#FFF");
                var kongjian_vaule=$.trim($(kongjian_name).val());
                var kongjian_vaule_length=kongjian_vaule.length;
                if(kongjian_vaule_length==0)
                {
                    set_msg(kongjian_name+"_msg","on_error on_show","您还没有输入确认密码");
                    return false;
                }
                else
                {
                    if(kongjian_vaule == $.trim($("#password_txb").val()))
                    {
                        set_msg(kongjian_name+"_msg","on_ok on_show","输入正确");
                        return true;
                    }
                    else
                    {
                        set_msg(kongjian_name+"_msg","on_error on_show","密码不一致，请再次确认");
                        return false;
                    }
                }
            }
        }
        
        //手机验证
        function check_shouji(check_type)
        {
            var kongjian_name="#shouji_txb";
            if(check_type==1)//onfocus
            {
                $(kongjian_name).css("background-color","#FEFFE3");
                set_msg(kongjian_name+"_msg","on_attention on_show","请输入您的手机号码");
            }
            else//onblur
            {
                $(kongjian_name).css("background-color","#FFF");
                var kongjian_vaule=$.trim($(kongjian_name).val());
                var kongjian_vaule_length=kongjian_vaule.length;
                if(kongjian_vaule_length==0)
                {
                    set_msg(kongjian_name+"_msg","on_error on_show","您还没有输入手机号码");
                    return false;
                }
                else
                {
                    var regu = /^1(3|4|5|8)\d{9}$/;
                    if (regu.test(kongjian_vaule))
                    {
                        htmlobj=$.ajax({url:"http://localhost:8080/guanganren/user/user!check.do?type=phone&phone="+ kongjian_vaule,async:false});
                        
                        if(htmlobj.responseText=="true")
                        {
                            set_msg(kongjian_name+"_msg","on_ok on_show","输入正确，请点击获取手机验证码");
                            return true;
                        }
                        else
                        {
                            set_msg(kongjian_name+"_msg","on_error on_show","该手机号码已经被使用，请更换！");
                            return false;
                        }
                    }
                    else
                    {
                        set_msg(kongjian_name+"_msg","on_error on_show","手机号码格式不正确,请输入正确的手机号！");
                        return false;
                    }
                }
            }
        }
        
        //手机验证
        function check_shoujiyzm()
        {
            var kongjian_name="#shouji_yzm_txb";
            var kongjian_vaule=$.trim($(kongjian_name).val());
            var kongjian_vaule_length=kongjian_vaule.length;
            if(kongjian_vaule_length==0)
            {
                set_msg(kongjian_name+"_msg","on_error on_show","您还没有输入验证码");
                return false;
            }
            else
            {
                set_msg(kongjian_name+"_msg","on_attention on_hidden","");
                return true;
            }
        }
        
        
            function time()
            {
                $("#shouji_yzm_txb_msg").show();
                $("#Button2").hide();    
                var num = 180; // 倒计时时间 
                $("#count").html(num); // 初期值设置
                function changeTime()
                {
                    if(num > 0)
                    {
                       num = num - 1;
                       curnum = num;
                      $("#shouji_yzm_txb_msg").html("距离下次发送验证需要"+curnum+"秒");
                   }
                   else
                   {
                       if(num == 0)
                       {
                         $("#shouji_yzm_txb_msg").hide();   // 到时间后的操作
                         $("#Button2").show();
                         clearInterval(num);    
                       }
                       num = num - 1;
                    }
                }
                setInterval(changeTime,1000);
            }
            
            
            function timestop()
            {
                clearInterval(num);
            }
            
    
        
        
        //电子邮箱验证
        function check_email(check_type)
        {
            var kongjian_name="#email_txb";
            if(check_type==1)//onfocus
            {
                $(kongjian_name).css("background-color","#FEFFE3");
                set_msg(kongjian_name+"_msg","on_attention on_show","请输入有效的电子邮箱，可用于登录和找回密码");
            }
            else//onblur
            {
                $(kongjian_name).css("background-color","#FFF");
                var kongjian_vaule=$.trim($(kongjian_name).val());
                var kongjian_vaule_length=kongjian_vaule.length;
                if(kongjian_vaule_length==0)
                {
                    set_msg(kongjian_name+"_msg","on_error on_show","您还没有输入电子邮箱");
                    return false;
                }
                else
                {
                    var regu = /^([a-zA-Z0-9]+[_|\_|\.-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                    if (regu.test(kongjian_vaule))
                    {
                        htmlobj=$.ajax({url:"http://localhost:8080/guanganren/user/user!check.do?type=email&email="+ kongjian_vaule,async:false});
                        if(htmlobj.responseText=="true")
                        {
                            set_msg(kongjian_name+"_msg","on_ok on_show","输入正确");
                            return true;
                        }
                        else
                        {
                            set_msg(kongjian_name+"_msg","on_error on_show","该电子邮箱已经被使用，请更换！");
                            return false;
                        }
                    }
                    else
                    {
                        set_msg(kongjian_name+"_msg","on_error on_show","电子邮箱格式不正确");
                        return false;
                    }
                }
            }
        }
        
        
        
